<?php
class model_feeds extends CI_Model {

	public function __construct()
	{
	//ini_set('memory_limit', '-1');
		$this->load->library('fclass');
		$this->load->database();
	}


	public function select($data)
	{
		//echo $this->fclass->test();
		$this->db->select('*');
		$this->db->from('tbl_feeds');
		$this->db->join('tbl_customers', 'tbl_customers.cust_id = tbl_feeds.feed_cust_id');
		//$this->db->join('tblusers', 'tblusers.uId = tbl_feeds.feed_creator_id');

		if(isset($data["feed_creator_id"])&&$data["feed_creator_id"]!="")
			$this->db->where('feed_creator_id',$data["feed_creator_id"]);
			//$data["cust_creator_id"]= $data["cust_creator_id"];

		if(isset($data["cust_id"])&&$data["cust_id"]!="")
			$this->db->where('cust_id',$data["cust_id"]);

		if(isset($data["feed_create_time"])&&$data["feed_create_time"]!="")
			$this->db->where('cust_create_time >=',$data["cust_create_time"]);

		if(isset($data["feed_action_time"])&&$data["feed_action_time"]!="")
			$this->db->where('feed_action_time >=',$data["feed_action_time"]);


		$this->db->order_by("feed_create_time","desc");
		$this->db->limit($data["limit"], $data["paging"]);
		$query = $this->db->get();
		//echo $this->db->last_query();
		//print_r($query);
		return $query->result_array();
	}

	public function selectCount($data)
	{
		$this->db->select('*');
		$this->db->from('tbl_feeds');
		$this->db->join('tbl_customers', 'tbl_customers.cust_id = tbl_feeds.feed_cust_id');

		if(isset($data["feed_creator_id"])&&$data["feed_creator_id"]!="")
			$this->db->where('feed_creator_id',$data["feed_creator_id"]);
			//$data["cust_creator_id"]= $data["cust_creator_id"];

		if(isset($data["cust_id"])&&$data["cust_id"]!="")
			$this->db->where('cust_id',$data["cust_id"]);


		if(isset($data["feed_create_time"])&&$data["feed_create_time"]!="")
			$this->db->where('feed_create_time >=',$data["feed_create_time"]);

		if(isset($data["feed_action_time"])&&$data["feed_action_time"]!="")
			$this->db->where('feed_action_time >=',$data["feed_action_time"]);
		

		$query = $this->db->get();
		//echo $this->db->last_query();
		//print_r($query);
		return $query->num_rows();		
	
	}

	public function insert($data)
	{
		$this->db->trans_start();
		$this->db->insert('tbl_feeds',$data); 
		$insert_id = $this->db->insert_id();
   		$this->db->trans_complete();
   		return $insert_id;
	}


	public function updateCustID($data,$id,$id_creator){
		if($id!="")
			$this->db->where('feed_cust_id', $id);

		if($id_creator!="")
			$this->db->where('feed_creator_id', $id_creator);

		$this->db->update('tbl_feeds', $data); 
	}

	public function deleteCustID($data){
		$this->db->delete('tbl_feeds', $data); 
	}


}

?>